function [IA_Scenario, consistent, max_depth] = IA_Network_Check_Consistency(IA_Network, i, j, depth)
%IA_Network_Check_Consistency function CC(M, i, j, depth)
%   Detailed explanation goes here

consistent = 0;
IA_Scenario = IA_Network;
max_depth = depth;

n = size(IA_Network.nodes, 2);
last_i = n - 1;
last_j = n;

% M' <- M
% for each atom ak E Mij do
for k = 1:13
  a = IA_Relation_Intersect(IA_Network.relations(i, j), IA_Relation_Number(k));
  if ~IA_Relation_Is_Null(a)
    % Mij <- ak
    % if PC( M ) then
    [IA_Temp, consistent] = IA_Network_Path_Consistency(IA_Network, i, j, a);
    if consistent
      % if i, j are last edges
      if ((i == last_i) && (j == last_j))
        % result[depth] <- ak; {store atomic label}
        IA_Scenario = IA_Temp;
        % return (true);
        return;
      else
        % or CC(M, next_i, next_j, depth + 1) then
        [next_i, next_j] = IA_Network_CC_Next_Relation(n, i, j);
        [IA_Temp, consistent, max_depth] = IA_Network_Check_Consistency(IA_Temp, next_i, next_j, depth + 1);
        if consistent
          % result[depth] <- ak; {store atomic label}
          IA_Scenario = IA_Temp;
          % return (true);
          return;
        end
      end
    end
  end
end
% return (false);
end